package com.siyao.redvip.ui.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import com.siyao.redvip.R;
import android.view.ViewGroup;
import android.content.Context;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.siyao.redvip.bean.ZxBean;
import com.siyao.redvip.components.view.LoadingDialog;
import com.siyao.redvip.image.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class ZxAdapter extends BaseAdapter{
	
	 protected Context mContext;
	 protected LoadingDialog pd;
	 protected List<ZxBean> mDatas;
	 private LayoutInflater mInflater;//加载list_item
	    
	 public ZxAdapter(Context context) {
	        this.mContext = context;
	        pd = new LoadingDialog(mContext);
	        pd.setCancelable(false);
	        mInflater = LayoutInflater.from(context);
	    }
	 
	 
	public void setmDatas(List<ZxBean> mDatas) {
		this.mDatas = mDatas;
	}

	@Override
	public int getCount() {
		 if (mDatas == null) {
	            return 0;
	        }
		return mDatas.size();
	}

	@Override
	public Object getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position <= 0 ? 0 :position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if(convertView ==null){
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.zx_list_item, null);
			holder.textView=(TextView)convertView.findViewById(R.id.textview_title);
			holder.imageView=(ImageView)convertView.findViewById(R.id.imv_title_pic);
			holder.time=(TextView)convertView.findViewById(R.id.textview_time);
			convertView.setTag(holder);			
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		if(mDatas.size()>0){
			ZxBean data  = mDatas.get(position);
			Integer id=data.getId();
			String title=data.getTitle();
			String titlePic=data.getTitlePic();
			String date = data.getDate();
			holder.textView.setText(title);
			holder.time.setText(date);
			ImageLoader.getInstance().displayImage("http://120.26.61.237:9009/VolunteersMgt/titlePicture/"+titlePic, holder.imageView,ImageLoaderOptions.getDefaultInstance());
		}
		return convertView;
	}
	
	private static class ViewHolder {
		TextView textView;        //数据显示区域
		ImageView imageView;
		TextView time ;//shijian
	}
	
	
    public void setDataChanged(List<ZxBean> mDatas) {
        if (mDatas != null && !mDatas.isEmpty()) {
            this.mDatas = mDatas;
            this.notifyDataSetChanged();
        }
    }

    public void clear() {
        if (mDatas != null && !mDatas.isEmpty()) {
            this.mDatas.clear();
        }
        this.notifyDataSetChanged();
    }
}
